package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.DailyNews;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IDailyNewsService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * index页面的搜索功能的控制器
 */
@RestController
@RequestMapping("search")
public class SearchController {

    //攻略数据
    @Autowired
    private IStrategyService strategyService;
    //资讯
    @Autowired
    private IDailyNewsService newsService;
    //游记
    @Autowired
    private ITravelService travelService;

    /**
     * 查询攻略的方法
     * @param qo 查询攻略的关键字
     * @return 单个攻略
     */
    @GetMapping(value = "/strategy/{keyword}")
    public Strategy queryForStrategy(QueryObject qo){
        Strategy strategy = new Strategy();
        List<Strategy> list = strategyService.queryForStrategy(qo);
        if (list!=null && list.size() > 0) {
            strategy = list.get(0);
        }
        return strategy;
    }

    /**
     *  查询日报的方法
     * @param qo 查询日报关键字
     * @return list 结果集
     */
    @GetMapping(value = "/news/{keyword}")
    public PageInfo<DailyNews> queryForDailyNews(QueryObject qo){
        PageInfo<DailyNews> list = newsService.queryForDailyNews(qo);
        return list;
    }

    /**
     * 查询游记的方法
     * @param qo 查询游记的关键字
     * @return list结果集
     */
    @GetMapping(value = "/travel/{keyword}")
    public PageInfo<Travel> queryForTravel(QueryObject qo){
        PageInfo<Travel> list = travelService.queryForTravel(qo);
        return list;
    }

}
